import parseTemplateToTokens from "./parseTemplateToTokens";
import renderTemplate from "./renderTemplate";
import {compressDomStr} from "./utils";

export default class TemplateEngine {

    constructor() {
        this.domStr = '';
    }

    render(templateStr, data) {
        const tokens = parseTemplateToTokens(templateStr);
        let domStr = renderTemplate(tokens, data);

        domStr = compressDomStr(domStr);
        this.domStr = domStr;

        return this;
    }

    $mounted(domName) {
        const dom = document.querySelector(domName);

        dom.innerHTML = this.domStr;
    }
}